'use strict';
const moment = require('moment');
const CryptoJS = require("crypto-js");

module.exports = {
  relativeTime : time => moment(new Date(time * 1000)).fromNow(),
  encrypt(data) {
    // sha1加密,ebook312
    const result = CryptoJS.HmacSHA1(JSON.stringify(data),this.config.keys).toString()
    return result;
  },
  localDate(v) {
    const d = new Date(v || Date.now());
    d.setMinutes(d.getMinutes() - d.getTimezoneOffset());
    return d.toISOString();
  },
  rndNum(n) {
    let rnd = '';
    for (let i = 0; i < n; i++) {
      rnd += Math.floor(Math.random() * 10);
    }
    return rnd;
  },
  // 章节表名字
  categoryTableName (bid){
    return 'category'+bid
  }
};
